package client

import (
	"context"
	"github.com/golang/protobuf/ptypes/empty"
	"github.com/micro/go-micro/v2/client"
	"github.com/micro/go-micro/v2/client/grpc"

	"kop/framework/wrapper"
	"kop/pb"
	"kop/pb/service"
)

var MailService service.MailService

func init() {

	var c = grpc.NewClient(client.Wrap(wrapper.ClientLogWrapper))
	_ = c.Init()

	MailService = service.NewMailService("go.micro.srv.mail", c)
}

//
func Send1(roleID int32, title, content string, attachment *pb.Award) error {

	var _, err = MailService.Send(context.Background(), &service.SendMailRequest{
		RoleIDs: []int32{roleID}, From: pb.MailFrom_System, Title: title, Content: content, Attachment: attachment})

	return err
}

func Send(roleIDs []int32, title, content string, attachment *pb.Award) error {

	var _, err = MailService.Send(context.Background(), &service.SendMailRequest{
		RoleIDs: roleIDs, From: pb.MailFrom_System, Title: title, Content: content, Attachment: attachment})

	return err
}

func SystemMail(roleIDs []int32, ID int32) (*empty.Empty, error) {

	return MailService.SystemMail(context.Background(), &service.SystemMailRequest{RoleIDs: roleIDs, ID: ID})
}
